const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  // 输出文件目录
  outputDir: 'wx-ai',
  publicPath: './',
  //不展示source-map文件
  productionSourceMap: false,
  //webpack打包配置
  chainWebpack: (config) => {
    //去除console.log
    config.optimization.minimizer('terser').tap((args) => {
      args[0].terserOptions.compress.drop_console = true
      return args
    })
    //移除预载插件
    config.plugins.delete('preload')
    //移除预取插件
    config.plugins.delete('prefetch')
    //图片压缩
    config.module
        .rule('images')
        .use('imageWebpackLoader')
        .loader('image-webpack-loader')
        .options({
          disable: process.env.NODE_ENV === 'development', // 开发环境下禁止压缩
          gifsicle: {
            interlaced: false
          }
        })
  },
  configureWebpack: config=>{
    //设置别名
    config.resolve={
      ...config.resolve,
      alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': path.resolve(__dirname, './src'),
      }
    },
        //设置不打包的文件
        config.externals= {
          'vue': 'Vue',
          'vue-router': 'VueRouter',
          'vuex': 'Vuex',
          'element-ui': 'ELEMENT',
        }
    //插件配置
    config.plugins = [
      ...config.plugins,
      // 开启 gzip 压缩
      new CompressionPlugin({
        filename: '[path][base].gz',
        algorithm: 'gzip',
        test: /\.js$|\.css$|\.html$/,
        threshold: 10240,
        minRatio: 0.8
      })
    ]
    config["performance"] = {//打包文件大小配置
      "maxEntrypointSize": 10000000,
      "maxAssetSize": 30000000
    }
  }
})
